<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller\Api;

use App\Middleware\JwtMiddleware;
use App\Model\Information;
use App\Model\InformationJobWanted;
use App\Model\Order;
use App\Model\System;
use App\Model\TopConfig;
use App\Model\User;
use App\Resource\InformationCollection;
use Hyperf\Database\Query\Builder;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;

#[Controller]
class InformationController
{
    #[Inject]
    protected ValidatorFactoryInterface $validationFactory;

    #[Inject]
    protected RequestInterface $request;

    #[RequestMapping(path: "", methods: "get")]
    public function list()
    {
        /** @var User $user */
        $user = auth()->user();
        $list = Information::query();

        if ($userId = $this->request->query('user_id')) {
            $list->where('status', '!=', 2);
            $list->where('user_id', $userId);
        } else {
            $list->active();
        }

        if ($type = $this->request->query('type')) {
            $list->where('type', $type);
        }

        if ($keyword = $this->request->query('keyword')) {
            $list->keyword($keyword);
            //加入搜索历史
            if ($user) {
                $count = $user->searchHistory()->where('search', $keyword)->count();
                if ($count <= 0) {
                    $history = $user->searchHistory()->make();
                    $history->search = $keyword;
                    $history->save();
                }
            }
        }

        $lat = $this->request->input('lat');
        $lng = $this->request->input('lng');
        //计算距离
        $list->selectRaw("*,ROUND(ACOS(
        SIN((${lat}  * 3.1415) / 180) * SIN((lat * 3.1415) / 180) 
        + COS((${lat} * 3.1415) / 180) * COS((lat * 3.1415) / 180) 
        * COS((${lng} * 3.1415) / 180 - (lng * 3.1415) / 180)
    ) * 6378 ,2) AS distance");

        $sort = $this->request->input('sort', 1);
        //按最新排序
        if ($sort == 1) {
            //置顶排序,优先置顶在前,其次为指定天数最多的在前,置顶付费金额最多的在前,最后才为最新
            $list->orderByDesc('is_top');
            $list->orderByDesc('top_days');
            $list->orderByDesc('top_total_count');
            $list->orderByDesc('create_time');
        } else {
            //按距离排序
            $list->orderBy('distance');
        }

        $list->with([
            'user' => function ($q) {
                /** @var Builder $q */
                $q->select(['id', 'nickname', 'mobile']);
                $q->with(['enterprise' => function ($q) {
                    $q->select(['id', 'name']);
                }]);
            },
            'ad', 'cp', 'freeRider', 'houseSales', 'jobWanted', 'pc', 'publicGood', 'recruitment', 'rent', 'solicit', 'imgs',
        ]);

//        return $list->toSql();
        $list = $list->paginate((integer)$this->request->query('page_num', 15));
        $data = [
            'list' => (new InformationCollection($list))->toListApi($user),
            'count' => $list->total(),
            'count_page' => $list->lastPage(),
            'page_num' => $list->perPage(),
        ];
        return self::jsonResponse(200, 'success', $data);
    }

    #[Middleware(JwtMiddleware::class)]
    #[RequestMapping(path: "add", methods: "post")]
    public function add()
    {
        $type = $this->request->input('type');
        switch ($type) {
            //人找车
            case 1:
                $data = $this->verifyPC($this->request->all());
                break;
            //车找人
            case 2:
                $data = $this->verifyPC($this->request->all());
                break;
            //顺风车
            case 3:
                $data = $this->verifyPC($this->request->all());
                break;
            //求职
            case 4:
                $data = $this->verifyJobWanted($this->request->all());
                break;
            //租房
            case 5:
                $data = $this->verifyRent($this->request->all());
                break;
            //售房
            case 6:
                $data = $this->verifyHouseSales($this->request->all());
                break;
            //广告
            case 7:
                $data = $this->verifyAd($this->request->all());
                break;
            //公益
            case 8:
                $data = $this->verifyAd($this->request->all());
                break;
            //招聘
            case 9:
                $data = $this->verifyRecruitment($this->request->all());
                break;
            //求租
            case 10:
                $data = $this->verifyAd($this->request->all());
                break;
            default:
                return self::jsonResponse(400, '信息类型不存在');
                break;
        }

        if (($data['code'] ?? '') == 422) {
            return self::jsonResponse(422, ($data['message'] ?? '信息验证失败'));
        }

        $infoData = $data['infoData'] ?? [];
        $mainData = $data['mainData'] ?? [];
        $mainData['all_type'] = $type;
        $mainData['type'] = $type;

        if ($type == 10) {
            $mainData['type'] = 5;
        }

        if ($type == 9) {
            $mainData['type'] = 4;
        }

        $imgIds = $mainData['img_ids'] ?? [];
        unset($mainData['img_ids']);

        $information = new Information($mainData);
        $information->user()->associate(auth()->user());
        if ($mainData['top_days'] > 0) {
            $information->status = 2;
        }
        $information->save();
        if (is_array($imgIds) && count($imgIds) > 0) {
            $information->imgs()->sync($imgIds);
        }

        $info = $information->makeInfo();
        $info->fill($infoData);
        $info->save();


        return self::jsonResponse(200, '发布成功', ['information_id' => $information->id]);
    }

    /**
     * 人找车/车找人/顺风车验证字段
     * @param $request
     * @return array|array[]
     */
    public function verifyPC($request)
    {
        $data = $this->validationFactory->make(
            $request,
            [
                'origin' => 'required',
                'origin_lat' => 'required',
                'origin_lng' => 'required',
                'destination' => 'required',
                'destination_lat' => 'required',
                'destination_lng' => 'required',
                'time' => 'required|date',
                'number' => 'required|integer|min:1',
                'content' => 'required',
                'img_ids' => '',
                'lat' => 'required',
                'lng' => 'required',
                'username' => 'required',
                'mobile' => 'required',
                'top_days' => 'nullable|integer|min:0'
            ],
            [
                'origin.required' => '请填写出发地',
                'origin_lat.required' => '获取出发地坐标失败',
                'origin_lng.required' => '获取出发地坐标失败',
                'destination.required' => '请填写到达地',
                'destination_lat.required' => '获取到达地坐标失败',
                'destination_lng.required' => '获取到达地坐标失败',
                'time.required' => '请选择时间',
                'time.date' => '时间格式不正确',
                'number.required' => '请填写人数',
                'number.integer' => '人数格式不正确',
                'number.min' => '人数最少为1人',
                'content.required' => '请填写发布详情',
                'lat.required' => '获取当前位置失败',
                'lng.required' => '获取当前位置失败',
                'username.required' => '请填写联系人姓名',
                'mobile.required' => '请填写联系电话',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return ['code' => 422, 'message' => $data->errors()->first()];
        }

        $data = $data->validated();
        $infoData = [
            'origin' => $data['origin'],
            'origin_lat' => $data['origin_lat'],
            'origin_lng' => $data['origin_lng'],
            'destination' => $data['destination'],
            'destination_lat' => $data['destination_lat'],
            'destination_lng' => $data['destination_lng'],
            'time' => $data['time'],
            'number' => $data['number'],
            'content' => $data['content'] ?? '',
        ];

        if (($data['img_ids'] ?? '') && is_string(($data['img_ids'] ?? ''))) {
            $data['img_ids'] = explode(',', $data['img_ids']);
        }

        $mainData = [
            'username' => $data['username'],
            'img_ids' => $data['img_ids'],
            'mobile' => $data['mobile'],
            'top_days' => $data['top_days'] ? $data['top_days'] : 0, 'lat' => $data['lat'] ?? '',
            'lng' => $data['lng'] ?? '',
        ];

        return [
            'infoData' => $infoData,
            'mainData' => $mainData
        ];
    }

    /**
     * 添加求职信息字段验证
     * @param $request
     * @return array|array[]
     */
    public function verifyJobWanted($request)
    {
        $data = $this->validationFactory->make(
            $request,
            [
                'name' => 'required',
                'sex' => 'required',
                'qualification' => 'required',
                'university' => 'required',
                'birthday' => 'required',
                'city_id' => 'required',
                'trade_id' => 'required',
                'pay' => 'nullable|numeric|min:0',
                'work_experience' => '',
                'education' => '',
                'content' => '',
                'img_id' => '',
                'img_ids' => '',
                'lat' => 'required',
                'lng' => 'required',
                'username' => 'required',
                'mobile' => 'required',
                'top_days' => 'nullable|integer|min:0'
            ],
            [
                'name.required' => '请填写姓名',
                'sex.required' => '请选择性别',
                'qualification.required' => '请选择学历',
                'university.required' => '请填写毕业院校',
                'birthday.required' => '请选择出生年份',
                'city_id.required' => '请选择期望工作地点',
                'trade_id.required' => '请选择行业',
                'pay.numeric' => '期望薪资格式不正确',
                'pay.min' => '期望薪资格式不正确',
                'lat' => 'required',
                'lng' => 'required',
                'username.required' => '请填写联系人姓名',
                'mobile.required' => '请填写联系电话',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return ['code' => 422, 'message' => $data->errors()->first()];
        }

        $data = $data->validated();
        $infoData = [
            'name' => $data['name'],
            'sex' => $data['sex'],
            'qualification' => $data['qualification'],
            'university' => $data['university'],
            'city_id' => $data['city_id'],
            'trade_id' => $data['trade_id'],
            'pay' => $data['pay'] ?? null,
            'work_experience' => $data['work_experience'] ?? '',
            'education' => $data['education'] ?? '',
            'content' => $data['content'] ?? '',
            'img_id' => $data['img_id'] ? $data['img_id'] : null,
        ];

        if (($data['img_ids'] ?? '') && is_string(($data['img_ids'] ?? ''))) {
            $data['img_ids'] = explode(',', $data['img_ids']);
        }

        $mainData = [
            'username' => $data['username'],
            'img_ids' => $data['img_ids'],
            'mobile' => $data['mobile'],
            'top_days' => $data['top_days'] ? $data['top_days'] : 0, 'lat' => $data['lat'] ?? '',
            'lng' => $data['lng'] ?? '',
        ];

        return [
            'infoData' => $infoData,
            'mainData' => $mainData
        ];
    }

    /**
     * 添加出租信息字段验证
     * @param $request
     * @return array|array[]
     */
    public function verifyRent($request)
    {
        $data = $this->validationFactory->make(
            $request,
            [
                'title' => 'required',
                'address' => 'required',
                'address_lat' => 'required',
                'address_lng' => 'required',
                'total' => 'required|numeric|min:0',
                'rent_type' => 'required',
                'content' => '',
                'img_ids' => '',
                'lat' => 'required',
                'lng' => 'required',
                'username' => 'required',
                'mobile' => 'required',
                'top_days' => 'nullable|integer|min:0'
            ],
            [
                'title.required' => '请填写标题',
                'address.required' => '请填写地址',
                'address_lat.required' => '获取地址定位失败',
                'address_lng.required' => '获取地址定位失败',
                'total.required' => '请填写价格',
                'total.numeric' => '价格格式不正确',
                'total.min' => '价格格式不正确',
                'rent_type.required' => '请选择出租类型',
                'lat.required' => '获取当前位置失败',
                'lng.required' => '获取当前位置失败',
                'username.required' => '请填写联系人姓名',
                'mobile.required' => '请填写联系电话',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return ['code' => 422, 'message' => $data->errors()->first()];
        }

        $data = $data->validated();
        $infoData = [
            'title' => $data['title'],
            'address' => $data['address'],
            'address_lat' => $data['lat'],
            'address_lng' => $data['lng'],
            'total' => $data['total'],
            'rent_type' => $data['rent_type'],
            'content' => $data['content'] ?? '',
        ];

        if (($data['img_ids'] ?? '') && is_string(($data['img_ids'] ?? ''))) {
            $data['img_ids'] = explode(',', $data['img_ids']);
        }

        $mainData = [
            'username' => $data['username'],
            'img_ids' => $data['img_ids'],
            'mobile' => $data['mobile'],
            'top_days' => $data['top_days'] ? $data['top_days'] : 0, 'lat' => $data['lat'] ?? '',
            'lng' => $data['lng'] ?? '',
        ];

        return [
            'infoData' => $infoData,
            'mainData' => $mainData
        ];
    }

    /**
     * 添加售房信息字段验证
     * @param $request
     * @return array|array[]
     */
    public function verifyHouseSales($request)
    {
        $data = $this->validationFactory->make(
            $request,
            [
                'title' => 'required',
                'city_id' => 'required',
                'village' => 'required',
                'address' => 'required',
                'address_lat' => 'required',
                'address_lng' => 'required',
                'area' => 'required|numeric|min:0',
                'total' => 'required|numeric|min:0',
                'house_type' => 'required',
                'content' => '',
                'img_ids' => '',
                'lat' => 'required',
                'lng' => 'required',
                'username' => 'required',
                'mobile' => 'required',
                'top_days' => 'nullable|integer|min:0'
            ],
            [
                'title.required' => '请填写标题',
                'city_id.required' => '请选择区域',
                'village.required' => '请填写小区名称',
                'address.required' => '请填写地址',
                'address_lat.required' => '获取地址定位失败',
                'address_lng.required' => '获取地址定位失败',
                'area.required' => '请填写面积',
                'area.numeric' => '面积格式不正确',
                'area.min' => '面积格式不正确',
                'total.required' => '请填写价格',
                'total.numeric' => '价格格式不正确',
                'total.min' => '价格格式不正确',
                'house_type.required' => '请填写户型',
                'lat.required' => '获取当前位置失败',
                'lng.required' => '获取当前位置失败',
                'username.required' => '请填写联系人姓名',
                'mobile.required' => '请填写联系电话',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return ['code' => 422, 'message' => $data->errors()->first()];
        }

        $data = $data->validated();
        $infoData = [
            'title' => $data['title'],
            'city_id' => $data['city_id'],
            'village' => $data['village'],
            'address' => $data['address'],
            'address_lat' => $data['address_lat'],
            'address_lng' => $data['address_lat'],
            'area' => $data['area'],
            'total' => $data['total'],
            'house_type' => $data['house_type'],
            'content' => $data['content'] ?? '',
        ];

        if (($data['img_ids'] ?? '') && is_string(($data['img_ids'] ?? ''))) {
            $data['img_ids'] = explode(',', $data['img_ids']);
        }

        $mainData = [
            'username' => $data['username'],
            'img_ids' => $data['img_ids'],
            'mobile' => $data['mobile'],
            'top_days' => $data['top_days'] ? $data['top_days'] : 0,
            'lat' => $data['lat'] ?? '',
            'lng' => $data['lng'] ?? '',
        ];

        return [
            'infoData' => $infoData,
            'mainData' => $mainData
        ];
    }

    /**
     * 添加广告/公益信息字段验证
     * @param $request
     * @return array|array[]
     */
    public function verifyAd($request)
    {
        $data = $this->validationFactory->make(
            $request,
            [
                'content' => '',
                'img_ids' => '',
                'lat' => 'required',
                'lng' => 'required',
                'username' => 'required',
                'mobile' => 'required',
                'top_days' => 'nullable|integer|min:0'
            ],
            [
                'lat.required' => '获取当前位置失败',
                'lng.required' => '获取当前位置失败',
                'username.required' => '请填写联系人姓名',
                'mobile.required' => '请填写联系电话',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return ['code' => 422, 'message' => $data->errors()->first()];
        }

        $data = $data->validated();
        $infoData = [
            'content' => $data['content'] ?? '',
        ];

        if (($data['img_ids'] ?? '') && is_string(($data['img_ids'] ?? ''))) {
            $data['img_ids'] = explode(',', $data['img_ids']);
        }

        $mainData = [
            'username' => $data['username'],
            'img_ids' => $data['img_ids'],
            'mobile' => $data['mobile'],
            'top_days' => $data['top_days'] ? $data['top_days'] : 0, 'lat' => $data['lat'] ?? '',
            'lng' => $data['lng'] ?? '',
        ];

        return [
            'infoData' => $infoData,
            'mainData' => $mainData
        ];
    }

    /**
     * 添加招聘信息字段验证
     * @param $request
     * @return array|array[]
     */
    public function verifyRecruitment($request)
    {
        /** @var User $user */
        $user = auth()->user();
        if ($user->is_enterprise_certification == -1) {
            return ['code' => 400, 'message' => '请先完成企业认证后再发布'];
        }
        $data = $this->validationFactory->make(
            $request,
            [
                'name' => 'required',
                'city_id' => 'required',
                'pay' => 'nullable|numeric|min:0',
                'duty' => 'required',
                'material_benefits' => '',
                'img_ids' => '',
                'lat' => 'required',
                'lng' => 'required',
                'username' => 'required',
                'mobile' => 'required',
                'top_days' => 'nullable|integer|min:0'
            ],
            [
                'name.required' => '请填写岗位名称',
                'city_id.required' => '请选择工作地点',
                'pay.numeric' => '薪资待遇格式不正确',
                'pay.min' => '薪资待遇格式不正确',
                'duty.required' => '请填写岗位职责',
                'username.required' => '请填写联系人姓名',
                'lat.required' => '获取当前位置失败',
                'lng.required' => '获取当前位置失败',
                'mobile.required' => '请填写联系电话',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return ['code' => 422, 'message' => $data->errors()->first()];
        }

        $data = $data->validated();
        $infoData = [
            'enterprise_id' => $user->enterprise->id ?? '',
            'name' => $data['name'],
            'city_id' => $data['city_id'],
            'pay' => $data['pay'],
            'duty' => $data['duty'],
            'material_benefits' => $data['material_benefits'] ?? '',
        ];

        if (($data['img_ids'] ?? '') && is_string(($data['img_ids'] ?? ''))) {
            $data['img_ids'] = explode(',', $data['img_ids']);
        }

        $mainData = [
            'username' => $data['username'],
            'img_ids' => $data['img_ids'],
            'mobile' => $data['mobile'],
            'top_days' => $data['top_days'] ? $data['top_days'] : 0, 'lat' => $data['lat'] ?? '',
            'lng' => $data['lng'] ?? '',
        ];

        return [
            'infoData' => $infoData,
            'mainData' => $mainData
        ];
    }

    #[RequestMapping(path: "detail", methods: "get")]
    /**
     * 信息详情
     * @return false|string
     */
    public function detail()
    {
        $id = $this->request->input('id');
        $information = Information::getById($id);
        if (!$information) {
            return self::jsonResponse(404, '数据不存在');
        }

        $information->views += 1;
        $information->save();

        return self::jsonResponse(200, 'success', $information->toApi(auth()->user()));
    }

    #[Middleware(JwtMiddleware::class)]
    #[RequestMapping(path: "edit", methods: "post")]
    public function edit()
    {
        $id = $this->request->input('id');
        /** @var User $user */
        $user = auth()->user();
        /** @var Information $information */
        $information = $user->information()->where('id', $id)->where('status', '!=', 2)->first();
        if (!$information) {
            return self::jsonResponse(404, '信息不存在');
        }
        switch ($information->all_type) {
            //人找车
            case 1:
                $data = $this->verifyPC($this->request->all());
                break;
            //车找人
            case 2:
                $data = $this->verifyPC($this->request->all());
                break;
            //顺风车
            case 3:
                $data = $this->verifyPC($this->request->all());
                break;
            //求职
            case 4:
                $data = $this->verifyJobWanted($this->request->all());
                break;
            //租房
            case 5:
                $data = $this->verifyRent($this->request->all());
                break;
            //售房
            case 6:
                $data = $this->verifyHouseSales($this->request->all());
                break;
            //广告
            case 7:
                $data = $this->verifyAd($this->request->all());
                break;
            //公益
            case 8:
                $data = $this->verifyAd($this->request->all());
                break;
            //招聘
            case 9:
                $data = $this->verifyRecruitment($this->request->all());
                break;
            //求租
            case 10:
                $data = $this->verifyAd($this->request->all());
                break;
            default:
                return self::jsonResponse(400, '信息类型不存在');
                break;
        }

        if (($data['code'] ?? '') == 422) {
            return self::jsonResponse(422, ($data['message'] ?? '信息验证失败'));
        }

        $infoData = $data['infoData'] ?? [];
        $mainData = $data['mainData'] ?? [];
        $imgIds = $mainData['img_ids'] ?? [];
        unset($mainData['img_ids']);

        $information = $information->fill($mainData);
        if ($mainData['top_days'] > 0) {
            $information->status = 2;
        }
        $information->save();

        if (is_array($imgIds) && count($imgIds) > 0) {
            $information->imgs()->sync($imgIds);
        }

        $info = $information->getInfoObject();
        $info->fill($infoData);
        $info->save();

        return self::jsonResponse(200, '编辑成功');

    }

    #[RequestMapping(path: "qualificationList", methods: "get")]
    /**
     * 学历列表
     * @return false|string
     */
    public function qualificationList()
    {
        $list = InformationJobWanted::$qualificationList;
        $data = [];
        foreach ($list as $k => $v) {
            $data[] = [
                'id' => $k,
                'name' => $v,
            ];
        }

        return self::jsonResponse(200, 'success', $data);
    }

    #[Middleware(JwtMiddleware::class)]
    #[RequestMapping(path: "handle", methods: "post")]
    /**
     * 上/下架
     * @return false|string
     */
    public function handle()
    {
        $id = $this->request->input('id');
        /** @var User $user */
        $user = auth()->user();
        /** @var Information $information */
        $information = $user->information()->where('id', $id)->where('status', '!=', 2)->first();
        if (!$information) {
            return self::jsonResponse(404, '信息不存在');
        }

        $information->handle();
        $information->save();

        return self::jsonResponse(200, 'success');
    }

    #[Middleware(JwtMiddleware::class)]
    #[RequestMapping(path: "delete", methods: "delete")]
    /**
     * 删除
     * @return false|string
     * @throws \Exception
     */
    public function delete()
    {
        $id = $this->request->input('id');
        /** @var User $user */
        $user = auth()->user();
        /** @var Information $information */
        $information = $user->information()->where('id', $id)->where('status', '!=', 2)->first();
        if (!$information) {
            return self::jsonResponse(404, '信息不存在');
        }

        $information->delete();

        return self::jsonResponse(200, 'success');
    }

    #[Middleware(JwtMiddleware::class)]
    #[RequestMapping(path: "top", methods: "post")]
    /**
     * 加热创建订单
     * @return false|string
     */
    public function top()
    {
        $id = $this->request->input('id');
        /** @var User $user */
        $user = auth()->user();
        /** @var Information $information */
        $information = $user->information()->where('id', $id)->where('status', '!=', 2)->first();
        if (!$information) {
            return self::jsonResponse(404, '信息不存在');
        }

        $data = $this->validationFactory->make(
            $this->request->all(),
            [
                'top_days' => 'required|integer|min:1'
            ],
            [
                'top_days.required' => '请选择置顶天数',
                'top_days.integer' => '置顶天数参数有误',
                'top_days.min' => '置顶天数参数有误',
            ]
        );

        if ($data->fails()) {
            return self::jsonResponse(422, $data->errors()->first());
        }

        $data = $data->validated();

        $information->status = 2;
        $information->top_days = $data['top_days'];
        $information->save();

        return self::jsonResponse(200, 'success', ['information_id' => $information->id]);
    }

    #[Middleware(JwtMiddleware::class)]
    #[RequestMapping(path: "likes", methods: "post")]
    /**
     * 点赞
     * @return false|string
     */
    public function likes()
    {
        $id = $this->request->input('id');
        /** @var User $user */
        $user = auth()->user();
        /** @var Information $information */
        $information = Information::getById($id);
        if (!$information) {
            return self::jsonResponse(404, '信息不存在');
        }

        $information->giveTheThumbsUp($user);

        return self::jsonResponse(200, 'success');
    }

    /**
     * 返回统一的json
     * @param int $status
     * @param $message
     * @param $data
     * @param $headerStatus
     * @return false|string
     */
    public static function jsonResponse(int $status = 1, $message = 'success', $data = null, $headerStatus = 200)
    {
        if (is_array($message)) {
            $data = $message;
            $message = 'success';
        }
        if (empty($data)) {
            $data = new class {
            };
        }

        return json_encode(['status' => $status, 'message' => $message, 'data' => $data]);

//        return response()->json(
//            ['status' => $status, 'message' => $message, 'data' => $data],
//            $headerStatus,
//            [],
//            JSON_UNESCAPED_UNICODE
//        );
    }
}
